package com.pwt.controller.basicsetting;

import com.pwt.annotation.Update;
import com.pwt.common.CustomException;
import com.pwt.common.ResultPage;
import com.pwt.entity.ProductAttribute;
import com.pwt.entity.ProductManage;
import com.pwt.model.ProductManageModel;
import com.pwt.service.ProductAttributeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author dw
 * @version 1.0.0
 * @date 2021/9/1
 */
@RestController
@Tag(name = "设置-产品属性")
public class ProductAttributeController {

    private ProductAttributeService productAttributeService;

    public ProductAttributeController(ProductAttributeService productAttributeService) {
        this.productAttributeService = productAttributeService;
    }

//    @GetMapping("attributes")
//    @Operation(description = "产品属性列表",summary = "产品属性列表")
//    @Parameters({
//            @Parameter(name = "name",description = "产品属性名称",required = false),
//            @Parameter(name = "limit",description = "展示数",required = true),
//            @Parameter(name = "page",description = "分页数",required = true)
//    })
//    public ResultPage getList(@RequestParam(value = "name",required = false) String name, @RequestParam(value = "page",required = true) Integer page,
//                              @RequestParam(value = "limit",required = true) Integer limit){
//        return this.productAttributeService.getList(name,page,limit);
//    }

    @GetMapping("attributes")
    @Operation(description = "产品属性列表",summary = "产品属性列表")
    @Parameter(name = "name",description = "产品属性名称",required = false)
    public List<ProductAttribute> getList(@RequestParam(value = "name",required = false) String name){
        return this.productAttributeService.getList(name);
    }

    @PostMapping("attribute")
    @Operation(description = "新增产品属性对象",summary = "新增产品属性对象")
    public ProductAttribute add(@RequestBody @Validated ProductAttribute productManage) throws CustomException {
        return this.productAttributeService.add(productManage);
    }

    @PutMapping("attribute")
    @Operation(description = "修改产品属性对象",summary = "修改产品属性对象")
    public ProductAttribute  update(@RequestBody @Validated(value = Update.class) ProductAttribute productManage) throws CustomException {
        return this.productAttributeService.update(productManage);
    }

    @DeleteMapping("/attribute/{id}")
    @Operation(description = "删除产品属性对象根据id",summary = "删除产品属性对象根据id")
    public void  delete(@Parameter(name = "id", description = "产品属性对象id")  @PathVariable(required = true) String id) throws CustomException {
        this.productAttributeService.delete(id);
    }

}
